#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
#include <iostream>

using namespace std;

class Solution02 {
public:
    int maxProfit(vector<int>& prices) {
        int n = prices.size();
        vector<vector<int>> dp(n, vector<int>(3));
        dp[0][0] = prices[0] * (-1);
        dp[0][1] = dp[0][2] = 0;
        for (int i = 1; i < n; i++) {
            dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] - prices[i]);
            dp[i][1] = max(dp[i - 1][2], dp[i - 1][1]);
            dp[i][2] = dp[i - 1][0] + prices[i];
        }
        return max(dp[n - 1][2], dp[n - 1][1]);
    }
};

class Solution01 {
public:
    int minCost(vector<vector<int>>& costs) {
        int n = costs.size();
        // vector<vector<int>> dp(n + 1, vector(5, INT_MAX));
        // for (int i = 0; i < 5; i++)
        //     dp[0][1] = 0;
        // for (int i = 1; i <= n; i++)
        //     for (int j = 1; j <= 3; j++) {
        //         dp[i][j] = costs[i - 1][j - 1] + min(dp[i - 1][j - 1], dp[i - 1][j + 1]);
        //     }
        // int ret = INT_MAX;
        // for (int i = 1; i < 4; i++)
        //     ret = min(ret, dp[n][i]);
        // return ret;
        vector<vector<int>> dp(n + 1, vector<int>(3));
        for (int i = 1; i <= n; i++) {
            dp[i][0] = costs[i - 1][0] + min(dp[i - 1][1], dp[i - 1][2]);
            dp[i][1] = costs[i - 1][1] + min(dp[i - 1][0], dp[i - 1][2]);
            dp[i][2] = costs[i - 1][2] + min(dp[i - 1][1], dp[i - 1][0]);
        }
        int ret = INT_MAX;
        return min(dp[n][0], min(dp[n][1], dp[n][2]));

    }
};

int main() {

    return 0;
}